package com.example.towSpringBoot.controller;


import com.example.towSpringBoot.annotation.RequiredPermission;
import com.example.towSpringBoot.common.PageResult;
import com.example.towSpringBoot.common.Result;
import com.example.towSpringBoot.dto.AdminDto;
import com.example.towSpringBoot.dto.EmployeeDto;
import com.example.towSpringBoot.dto.EmployeePageQueryDto;
import com.example.towSpringBoot.dto.EmployeeRoleDto;
import com.example.towSpringBoot.service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xinTong
 * @since 2024-01-23
 */
@RestController
@RequestMapping("api/employee")
public class EmployeeController {

    @Autowired
    private EmployeeService employeeService;

    /**
     * 员工查询
     * @param
     * @return
     */
/*    @GetMapping("list")
    public Result list(@Param(value = "pageNum")int pageNum,
                       @Param(value = "pageSize")int pageSize){
        PageResult result = employeeService.list(pageNum, pageSize);

        return Result.success(result);
    }*/

    @GetMapping("list")
    @RequiredPermission(name = "部门列表",expression = "department:delete")
    public Result list(EmployeePageQueryDto queryDto){
        PageResult result = employeeService.list(queryDto);
        return Result.success(result);
    }

    /**
     * 删除员工
     * @param id
     */
    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable Long id){
        employeeService.delete(id);
        return Result.success();
    }

    /**
     * 获取员工详细信息
     * @param id
     * @return
     */
    @GetMapping("/info/{id}")
    public Result info(@PathVariable Long id){
        EmployeeDto employeeDto = employeeService.info(id);
        return Result.success(employeeDto);
    }

    /**
     * 更新或者新增员工信息
     * @param employeeRoleDto
     */
    @PostMapping("/saveOrUpdate")
    public Result saveOrUpdate(@RequestBody EmployeeRoleDto employeeRoleDto){

        employeeService.saveOrUpdate(employeeRoleDto);
        return Result.success("修改成功！",null);
    }

    /**
     * 更新为管理员
     * @param
     * @return
     */
    @PostMapping("/updateState")
    public Result updateState(@RequestBody AdminDto adminDto) {
        employeeService.updateState(adminDto);
        return Result.success("修改成功！",null);
    }
}
